
$(function () {
    // todos 获取新闻列表
    $.ajax({
        type: 'GET',
        url: 'http://www.liulongbin.top:3006/api/news',
        success({ data, msg, status }) {
            if (status !== 200) {
                return alert(msg)
            }
            const htmlstr=data.map(({ cmtcount, img, source, tags, time, title }) => {
                const d=tags.split(',')
                const w=d.map(item=>{
                    return`
                 <span>${item}</span>
                 `   
                }).join('')
                return `
                <div class="news-item">
                <img class="thumb" src='http://www.liulongbin.top:3006${img}' alt="" />
                <div class="right-box">
                <h1 class="title">${title}</h1>
                <div class="tags">
                   ${w}
                </div>
                   <div class="footer">
                     <div>
                        <span>${source}</span>&nbsp;&nbsp;
                        <span>${time}</span>
                        </div>
                        <span>评论数：${cmtcount}</span>
                     </div>
                    </div>
                </div>   
     `
            }).join('')
            $('#news-list').html(htmlstr)
        }
    })

})
